clear

/*
use "C:\Local\数据\ex2005 data.dta"

egen ownership = group(firmtype)

egen country = group(partner)

egen id = group(hs8) 
egen cid = group(hs8 country)
egen ocid = group(hs8 country ownership)
egen oid = group(ownership hs8)

//ownership 1-Chinese foreign cooperative enterprises中外合作企业/2-sino-foreign equity joint venture中外合资企业
//3-Other 其它/4-state-owned enterprises (SOE)国有企业/5-Wholly Foreign-owned Enterprise( WFOE)
//外商独资企业/6-private business私营企业/7-collective enterprise集体企业

gen o2=.
    replace o2 = 1 if ownership ==4
	replace o2 = 2 if ownership ==1|ownership ==2|ownership ==5
	replace o2 = 3 if ownership ==6|ownership ==7|ownership ==3

g p = value/quantity
    drop if p==.
    bys o2 hs8: egen p97 = pctile(p), p(95)
	bys o2 hs8: egen p3 = pctile(p), p(5)
	drop if p>p97
	drop if p<p3
		
	g lp = log(p)

	bys firmid: egen totv = sum(value)
	g ltotv1 = log(totv)
	g ltotv2 = ltotv1^2
	g ltotv3 = ltotv1^3
	g ltotv4 = ltotv1^4

drop productcode unit firmid zip firm location firmtype partner tradetype value ///
quantity price year ownership country id cid o2 p p97 p3 totv

save "C:\Local\数据\Table 2\table 2 data.dta"

*/
	
areg lp trader, a(oid) cluster(hs8)

areg lp trader ltotv*, a(oid) cluster(hs8)
			
areg lp trader ltotv*, a(ocid) cluster(hs8)
